<div class="px-3 py-12">
    <h2 class="text-3xl font-semibold leading-7 text-indigo-600 text-center">Billing</h2>
    <%= if @plan.id == :enterprise do %>
        <p class="mx-auto mt-6 max-w-2xl text-center text-lg leading-8 text-gray-600">
            Thank you for using Azimutt.
            You are currently on <span title={@organization.plan_status}><%= AzimuttWeb.LayoutView.plan_badge(@plan.id) %></span><br>
            For any change or question, please contact <a href={"mailto:#{Azimutt.config(:enterprise_support_email)}"} class="underline text-indigo-600 hover:text-indigo-900"><%= Azimutt.config(:enterprise_support_email) %></a>.
        </p>
    <% else %>
        <p class="mx-auto mt-6 max-w-2xl text-center text-lg leading-8 text-gray-600">
            Thank you for using Azimutt.
            You are currently on <span title={@organization.plan_status}><%= AzimuttWeb.LayoutView.plan_badge(@plan.id) %></span>
            <%= if @organization.plan_seats > 1 do %>
                with <b><%= @organization.plan_seats %> seats</b>.
            <% end %>
            <br>
            More details on <a href={Routes.website_path(@conn, :pricing)} target="_blank" rel="noopener noreferrer" class="underline">pricing page</a>.
            Don't hesitate to <a href={"mailto:#{Azimutt.config(:contact_email)}"} class="underline">reach out</a> for any question.<br>
            <% max_seats = Azimutt.features().users[@plan.id] %>
            <%= if max_seats == nil || max_seats > 1 do %>
                Change your seats or plan using the "Manage your subscription" button.
            <% end %>
        </p>
        <%= if @plan.id == :pro do %>
            <div class="mt-3 max-w-xl mx-auto rounded bg-yellow-50 p-4">
                <div class="flex">
                    <div class="flex-shrink-0">
                        <Icon.exclamation_triangle kind="mini" class="h-5 w-5 text-yellow-400" />
                    </div>
                    <div class="ml-3">
                        <h3 class="my-0 text-sm font-medium text-yellow-800">This is a legacy plan.</h3>
                        <div class="mt-2 text-sm text-yellow-700">
                            Please migrate to the <a href={Routes.website_path(@conn, :pricing)} target="_blank" class="underline text-yellow-800 hover:text-yellow-900">new ones</a> as mentionned in the email.<br>
                            You will have to cancel it ("Manage your subscription") and subscribe again.
                        </div>
                    </div>
                </div>
            </div>
        <% end %>
        <div class="max-w-lg mx-auto">
            <%= if length(@subscriptions) > 1 do %>
                <div class="mt-3 rounded-md bg-yellow-50 p-4">
                    <div class="flex">
                        <div class="flex-shrink-0">
                            <Icon.exclamation_triangle kind="mini" class="h-5 w-5 text-yellow-400" />
                        </div>
                        <div class="ml-3">
                            <h3 class="my-0 text-sm font-medium text-yellow-800">You have <%= length(@subscriptions) %> subscriptions.</h3>
                            <div class="mt-2 text-sm text-yellow-700">
                                Having several subscriptions is not expected.<br>
                                Click on "Manage your subscription" below and cancel the bad one.
                            </div>
                            <div class="mt-2 text-sm text-yellow-700">
                                Your subscriptions:
                                <ul role="list" class="list-disc space-y-1 pl-5">
                                    <%= for subscription <- @subscriptions do %>
                                        <li><%= render "_subscription_show.html", subscription: subscription %></li>
                                    <% end %>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            <% end %>
            <!-- TODO: warn on trialing or cancel status -->
            <%= link "Manage your subscription", to: Routes.organization_billing_path(@conn, :edit, @organization.id), method: :post, class: "mt-6 inline-flex items-center px-4 py-2 border border-transparent shadow-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 sm:text-sm" %>
            <%= link "Refresh plan", to: Routes.organization_billing_path(@conn, :refresh, @organization.id), method: :post, title: "If your plan is out of sync, you can manually refresh it by clicking here.", class: "mt-3 block text-sm underline" %>
        </div>
    <% end %>
</div>
